package com.teemor.blog.controller;

import com.teemor.blog.api.ArticleApi;
import com.teemor.blog.entity.TbArticle;
import com.teemor.blog.entity.condition.TbArticleCondition;
import com.teemor.blog.model.ArticleIPo;
import com.teemor.blog.model.ArticleOPo;
import com.teemor.blog.service.IArticleService;
import com.teemor.common.bean.util.BeanConvertor;
import com.teemor.common.bean.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhoulk
 * @Description:
 * @date: 2019/7/23
 */
@RestController
@CrossOrigin
public class ArticleController implements ArticleApi {

    @Autowired
    IArticleService articleService;

    @Override
    public void addArticle(@RequestBody ArticleIPo inParam) {
        TbArticle article = BeanConvertor.convertBean(inParam, TbArticle.class);
        article.setCreateTime(DateUtil.newNowDate());
        articleService.addArticle(article);
    }

    @Override
    public void updArticle(@RequestBody ArticleIPo inParam) {
        TbArticle article = BeanConvertor.convertBean(inParam, TbArticle.class);
        articleService.updArticleById(article);
    }

    @Override
    public void delArticle(Integer atcId) {

    }

    @Override
    public ArticleOPo qryArticle(@PathVariable Integer atcId) {
        return BeanConvertor.convertBean(articleService.qryArticleById(atcId),ArticleOPo.class);
    }

    @Override
    public List<ArticleOPo> qryArticles(ArticleIPo inParam) {
        inParam.setAtcId(123);
        inParam.setTitle("测试数据");
        TbArticleCondition articleIPo = BeanConvertor.convertBean(inParam,TbArticleCondition.class);
        return BeanConvertor.convertBeanList(articleService.qryArticles(articleIPo),ArticleOPo.class);
    }
}
